package com.dwjm.shop.Jbp.Goods;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.math.BigDecimal;

@WebServlet("/addGoods")
public class GoodsHandler extends HttpServlet {


    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html;charset=UTF-8");
        resp.setCharacterEncoding("UTF-8");
//        获取商品信息
        String title=req.getParameter("title");
        String price=req.getParameter("price");
        String descr=req.getParameter("descr");
        String img=req.getParameter("img");
        String mid=req.getParameter("mid");
//        封装对象
        Goods goods=new Goods(null,title,new BigDecimal(price),descr,img,0,Integer.parseInt(mid));
        GoodsDao goodsDao=new GoodsDaoImpl();
        int i = goodsDao.addGoods(goods);
        if (1 == i) {
            resp.getWriter().write("Y");
        } else {
            resp.getWriter().write("N");
        }
    }
}